/*****************************************************************************************
Arise Engine		BoundingBox.cpp

					E-mail:		arise_engine@mail.ru

					Origin by:	DK Engine 0.019,
								KAIN (igor@donec.net), Agressor (agress0r@mail.ru)

created:			10.10.2005
last changes:		12.05.2007
*****************************************************************************************/
#include "stdafx.h"


aBoundingBox::aBoundingBox()
{
	m_max		= D3DXVECTOR3(0, 0, 0);
	m_min		= D3DXVECTOR3(0, 0, 0);
	m_center	= D3DXVECTOR3(0, 0, 0);
	m_size		= D3DXVECTOR3(0, 0, 0);
}
aBoundingBox::~aBoundingBox()
{
}


bool aBoundingBox::BuildFromVerticesList(const std::vector<D3DXVECTOR3> &vertices_list)
{
	if(vertices_list.empty()) return false;

	m_max = vertices_list[0];
	m_min = vertices_list[0];

	for(size_t vertex_iter = 0; vertex_iter < vertices_list.size(); vertex_iter++)
	{
		if(vertices_list[vertex_iter].x > m_max.x) m_max.x = vertices_list[vertex_iter].x;
		if(vertices_list[vertex_iter].x < m_min.x) m_min.x = vertices_list[vertex_iter].x;			
		if(vertices_list[vertex_iter].y > m_max.y) m_max.y = vertices_list[vertex_iter].y;
		if(vertices_list[vertex_iter].y < m_min.y) m_min.y = vertices_list[vertex_iter].y;			
		if(vertices_list[vertex_iter].z > m_max.z) m_max.z = vertices_list[vertex_iter].z;
		if(vertices_list[vertex_iter].z < m_min.z) m_min.z = vertices_list[vertex_iter].z;
	}
	
	
	m_size	= (m_max - m_min);///as 3dsmax / 2;
	m_center = m_min + m_size;
	
	//log(4, "m_max: %f~%f~%f", m_max.x, m_max.y, m_max.z);
	//log(4, "m_min: %f~%f~%f", m_min.x, m_min.y, m_min.z);
	//log(4, "m_size: %f~%f~%f", m_size.x, m_size.y, m_size.z);

	return true;
}




